package com.draem0507.refactor;

import java.util.Calendar;
import java.util.List;

/**
 * @title 引入契约检查
 * @desc
 * @atuh lwx
 * @createtime on 2015/11/14 15:32
 */
public class Day_25 {


    public class CashRegister {
        public int TotalOrder2(List<String> products, Calendar calendar)


        {

            if (products == null) {

                throw new NullPointerException("products must not be empty");
            }
            if (products.size() == 0) {

                throw new ArithmeticException("products's size must more than one");
            }
            //calendar校验省略

            int orderTotal = products.size();

            orderTotal += calendar.get(Calendar.SUNDAY);
            //输出校验
            if (orderTotal == 0) {

                throw new SecurityException("orderTotal's value must bigger than 0");
            }


            return orderTotal;
        }
    }

    public int TotalOrder(List<String> products, Calendar calendar) {
        int orderTotal = products.size();

        orderTotal += calendar.get(Calendar.SUNDAY);

        return orderTotal;
    }
}
